from appium.webdriver import Remote
from appium.webdriver.common.appiumby import AppiumBy

from page.base_page import BasePage
from page.contacts_page import ContactsPage


class WeWorkApp(BasePage):
    def __init__(self):
        super().__init__()
        # 启动应用参数
        caps = {
            "platformName": "android",
            "appium:appPackage" "com.tencent.wework",
            "appium:appActivity": "com.tencent.wework.launch.LaunchSplashActivity",
            "appium:noReset": "true"
        }
        self.driver = Remote(command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities=caps)
        self.driver.implicitly_wait(5)

    def to_contacts(self) -> ContactsPage:
        self.find(AppiumBy.CSS_SELECTOR, '[text="通讯录"]').click()
        return ContactsPage(self.driver)

    def close(self):
        self.driver.quit()